package jp.sourceforge.akjrcp.flvtools.basic.actions;

import jp.sourceforge.akjrcp.akj_betas.Akj_betasPlugin;
import jp.sourceforge.akjrcp.flvtools.basic.OpenDirectable;
import jp.sourceforge.akjrcp.flvtools.basic.SimpleView;

import org.eclipse.jface.action.IAction;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.IWorkbenchWindowActionDelegate;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.part.ViewPart;


/**
 * Our sample action implements workbench action delegate.
 * The action proxy will be created by the workbench and
 * shown in the UI. When the user tries to use the action,
 * this delegate will be created and execution will be 
 * delegated to it.
 * @see IWorkbenchWindowActionDelegate
 */
public class ShowLogAction implements IWorkbenchWindowActionDelegate {
	private IWorkbenchWindow window;
	/**
	 * The constructor.
	 */
	public ShowLogAction() {
		
	}

	/**
	 * The action has been activated. The argument of the
	 * method represents the 'real' action sitting
	 * in the workbench UI.
	 * @see IWorkbenchWindowActionDelegate#run
	 */
	public void run(IAction action) {
		
		LogDialog dialog=new LogDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
				"log",null,Akj_betasPlugin.getDefault().getProcessPrinter().getLog(),0,new String[]{"OK"},0);
		
		
		//
		dialog.open();
	}

	/**
	 * Selection in the workbench has been changed. We 
	 * can change the state of the 'real' action here
	 * if we want, but this can only happen after 
	 * the delegate has been created.
	 * @see IWorkbenchWindowActionDelegate#selectionChanged
	 */
	public void selectionChanged(IAction action, ISelection selection) {
	}

	/**
	 * We can use this method to dispose of any system
	 * resources we previously allocated.
	 * @see IWorkbenchWindowActionDelegate#dispose
	 */
	public void dispose() {
	}

	/**
	 * We will cache window object in order to
	 * be able to provide parent shell for the message dialog.
	 * @see IWorkbenchWindowActionDelegate#init
	 */
	public void init(IWorkbenchWindow window) {
		this.window = window;
	}
	
	public class LogDialog extends MessageDialog{

		private Text text;
		private String message;
		public LogDialog(Shell parentShell, String dialogTitle, Image dialogTitleImage, String dialogMessage, int dialogImageType, String[] dialogButtonLabels, int defaultIndex) {
			super(parentShell, dialogTitle, dialogTitleImage, "",
					dialogImageType, dialogButtonLabels, defaultIndex);
			message=dialogMessage;
			// TODO Auto-generated constructor stub
		}
		
		  protected Control createCustomArea(Composite parent) {
			  
			    GridData data=new GridData(GridData.FILL_BOTH);
			    data.minimumHeight=50;
			   
			    Composite panel=new Composite(parent,SWT.NULL);
			    //panel.setLayout(new RowLayout());
			    text = new Text(panel,SWT.MULTI|SWT.V_SCROLL|SWT.H_SCROLL);
				
			   panel.setLayoutData(data); 
			   text.setSize(420,200);
		        text.setText(message);
		        
		       
		      
		       // scroll.setLayoutData(data);
		       // scroll.setContent(text);
		       // scroll.setMinSize(320,240);
		        //scroll.setMinSize(parent.getClientArea().width,parent.getClientArea().height);
		        //scroll.setExpandHorizontal(true);
				//scroll.setExpandVertical(true);
		        return this.text;
		    }

	

	}
}